﻿using Lib.WPF.Controls;
using Lib.WPF.ViewModels;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Lib.WPF; 
/// <summary>
/// 登录界面程序
/// </summary>
public partial class Login {
    /// <summary>
    /// 
    /// </summary>
    public Login() {

        InitializeComponent();

        CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (Sender, e) => {
            WindowState = WindowState.Minimized;
        }));
        CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (Sender, e) => {
            WindowState = WindowState.Maximized;
        }));
        CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (Sender, e) => {
            WindowState = WindowState.Normal;
        }));
        CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (Sender, e) => {
            Close();
        }));

        MouseDown += (That, Args) => {
            DragMove();
        };

        DataContext = new ViewModels.LogOn();
    }
    /// <summary>
    /// 点击按钮时设置屏幕键盘的输入框与回车键的事件对象
    /// </summary>
    private void KeyPad_Click(object sender, RoutedEventArgs e) {
        SoftKeyBoard.Set(sender as UIElement, (this.DataContext as LogOn).Login);
    }
    /// <summary>
    /// 
    /// </summary>
    private void AccountBtn_Click(object sender, EventArgs e) {
        PopupAccounts.IsOpen = !PopupAccounts.IsOpen;
        if (DataContext is LogOn VM) {
            VM.IsPopupOpen = PopupAccounts.IsOpen;
        }
    }
}
